import java.util.*;
import java.io.*;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.*;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.ListSelectionModel;
import javax.swing.RowFilter;
import javax.swing.SpringLayout;
import javax.swing.SwingConstants;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.table.TableRowSorter;

public class ProcessClientPanel extends JPanel implements ActionListener {
	private JLabel firstNameL;
	private JLabel lastNameL;
	private JLabel DOBL; //Date Of Birth Label
	private JLabel ageL;
	private JLabel ethnicityL;
	private JLabel slash1; //slashes will be used for looks by deviding the date textfields
	private JLabel slash2;
	private JLabel slash3;
	private JLabel slash4;
	private JLabel dateLabel1; //this is a simple indicator of the date format mm-dd-yyyy
	private JLabel dateLabel2;
	private JLabel screenDateL;
	
	//these are for the text fields that the user will input
	private JTextField firstNameTF;
	private JTextField lastNameTF;
	private JTextField monthDOB;//these three are for date of birth
	private JTextField dayDOB;
	private JTextField yearDOB;
	private JTextField ageTF;
	private JTextField ethnicityTF;
	private JTextField monthSD; //this onward is for screen date
	private JTextField daySD;
	private JTextField yearSD;
	
	
	private JPanel format; //this will set the grid layout used
	private JPanel dobPanel; //this is for the date textfields which use their own format
	private JPanel buttonPanel; //for buttons which also no not follow the format
	private JPanel sdPanel;//this is for screen date textfields
	
	private GridBagConstraints c;
	
	//private JButton finishB;
	private JButton resetB;
	//private JButton saveB;
	
	//private GridLayout g;
	
	private ScreenedClient newClient;//these are used for creating new clients before adding them to the table
	private String f;
	private String l;
	private String d;
	private String m;
	private String y;
	private int a;
	private String e;
	
	private String sd;
	private String sm;
	private String sy;
	
	public ProcessClientPanel(){
	
		format = new JPanel(new GridLayout(8,2));
		format.setBackground(Color.WHITE);
		
		buttonPanel = new JPanel(new GridLayout(1,3));
		buttonPanel.setBackground(Color.WHITE);
		
		firstNameL = new JLabel("First Name"); //seting up labels
		lastNameL = new JLabel("Last Name");
		DOBL = new JLabel("Date of Birth");
		ageL = new JLabel("Age");
		ethnicityL = new JLabel("Ethnicity");
		slash1 = new JLabel("/");
		slash2 = new JLabel("/");
		slash3 = new JLabel("/");
		slash4 = new JLabel("/");
		dateLabel1 = new JLabel("mm-dd-yyyy ");
		dateLabel2 = new JLabel("mm-dd-yyyy ");
		screenDateL= new JLabel("Screening Date");
		
		
		firstNameTF = new JTextField(20); //setting up textfields
		lastNameTF = new JTextField(20);
		monthDOB = new JTextField("",2);
		dayDOB = new JTextField("",2);
		yearDOB = new JTextField("",4);
		ageTF = new JTextField(20);
		ethnicityTF = new JTextField(20);
		monthSD = new JTextField("",2);
		daySD = new JTextField("",2);
		yearSD = new JTextField("",4);
		
		c = new GridBagConstraints(); //this is used for dobPanel and sdPanel
		c.fill = GridBagConstraints.HORIZONTAL;
		
		dobPanel = new JPanel(new GridBagLayout());
		dobPanel.setBackground(Color.WHITE);
		dobPanel.add(dateLabel1,c);
		dobPanel.add(monthDOB,c);
		dobPanel.add(slash1,c);
		dobPanel.add(dayDOB,c);
		dobPanel.add(slash2,c);
		dobPanel.add(yearDOB,c);
		
		sdPanel = new JPanel(new GridBagLayout());
		sdPanel.setBackground(Color.WHITE);
		sdPanel.add(dateLabel2,c);
		sdPanel.add(monthSD,c);
		sdPanel.add(slash3,c);
		sdPanel.add(daySD,c);
		sdPanel.add(slash4,c);
		sdPanel.add(yearSD,c);
		
		resetB = new JButton("Reset");
		resetB.addActionListener(this);
		
		buttonPanel.add(resetB);
		
		format.add(firstNameL); //this will set up the panel that will be displayed
		format.add(firstNameTF);
		format.add(lastNameL);
		format.add(lastNameTF);
		format.add(DOBL);
		format.add(dobPanel);
		format.add(ageL);
		format.add(ageTF);
		format.add(ethnicityL);
		format.add(ethnicityTF);
		format.add(screenDateL);
		format.add(sdPanel);
		format.add(buttonPanel);
		
		this.setBackground(Color.WHITE);
		this.add(format);
		
	}
	
	public void actionPerformed(ActionEvent evt){
		
		if(evt.getSource() == resetB){
			clearTextFields();
		}	
	}
	
	public void getInfo(){ //this will instantly get info from all the textfields
		f = firstNameTF.getText();
		l = lastNameTF.getText();
		m = monthDOB.getText();
		d = dayDOB.getText();
		y = yearDOB.getText();
		try{
			a = Integer.parseInt(ageTF.getText());
		}
		catch(Exception e){
			System.out.println("Was not an Interger");
		}
		e = ethnicityTF.getText();
		sm = monthSD.getText();
		sd = daySD.getText();
		sy = yearSD.getText();
	}
	
	public String getFirstName(){
		return firstNameTF.getText();
	}
	
	public String getLastName(){
		return lastNameTF.getText();
	}
	
	public String getMonth(){ //these three are used for getting date of birth
		return monthDOB.getText(); 
	}
	
	public String getDate(){
		return dayDOB.getText();
	}
	
	public String getYear(){
		return yearDOB.getText();
	}
	
	public String getDateOfBirth(){
		return m + "-" + d + "-" + y;
	}
	
	public int getAge(){
		int i = -1;
		try{
			i = Integer.parseInt(ageTF.getText());
		}
		catch(Exception e){
			System.out.println("Was not an Interger");
		}
		return i;
	}
	
	public String getEthnicity(){
		return ethnicityTF.getText();
	}
	
	public String getSMonth(){ //these are used for getting screen date
		return monthSD.getText(); 
	}
	
	public String getSDate(){
		return daySD.getText();
	}
	
	public String getSYear(){
		return yearSD.getText();
	}
	
	public String getScreenDate(){
		return sm + "-" + sd + "-" + sy;
	}
		
	public void clearTextFields(){ //this will reset the textfields
		firstNameTF.setText("");
		lastNameTF.setText("");
		monthDOB.setText(""); 
		dayDOB.setText("");
		yearDOB.setText("");
		ageTF.setText(""); 
		ethnicityTF.setText("");
		monthSD.setText(""); 
		daySD.setText("");
		yearSD.setText("");
	}
				
	
	
}